/**
 * 
 */
package com.hurr.assembly;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;

import com.hurr.assembler.Assembler;
import com.hurr.bo.Saving;
import com.hurr.dto.SavingDto;

/**
 * @author Fernando Perelli
 *
 */
public class SavingAssembly {
	
	
	public SavingDto toDto(Saving saving) throws ClassNotFoundException, NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		SavingDto savingDto = new SavingDto();
		savingDto.setId(saving.getId());
		savingDto.setDate(saving.getDate());
		savingDto.setDescription(saving.getDescription());
		savingDto.setType(saving.getType());
		savingDto.setValue(saving.getValue());
		return savingDto;
	}
	
	public Saving toModel(SavingDto savingDto) throws InstantiationException, IllegalAccessException, ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException{
		Saving saving = new Saving();
		saving.setId(savingDto.getId());
		saving.setDate(savingDto.getDate());
		saving.setDescription(savingDto.getDescription());
		saving.setType(savingDto.getType());
		saving.setValue(savingDto.getValue());
		return saving;
	}

	public Collection<SavingDto> toDtos(Collection<Saving> savings) throws ClassNotFoundException, NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
		Collection<SavingDto> savingDtos = new ArrayList<SavingDto>();
		for (Saving saving : savings) {
			SavingDto savingDto = (SavingDto) Assembler.toDto(saving);
			savingDtos.add(savingDto);
		}
		return savingDtos;
	}
	
	public Collection<Saving> toModels(Collection<SavingDto> savingDtos) throws ClassNotFoundException, NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
		Collection<Saving> savings = new ArrayList<Saving>();
		
		for (SavingDto savingDto : savingDtos) {
			Saving saving= (Saving) Assembler.toModel(savingDto);
			savings.add(saving);
		}
		return savings;
		
	} 


}
